<template>
  <!-- 修改使用时间对话框 -->
  <el-dialog v-dialogDrag :title="dialogTitle" width="500px" :close-on-click-modal="false" :visible="dialogVisible" :before-close="cancel">
    <el-form :model="LookDialogForm" label-width="110px">
      <el-form-item label="企业到期时间">
        <el-date-picker
          v-model="LookDialogForm.enterpriseExpiryTime"
          style="width:340px;"
          type="date"
          clearable
          :picker-options="expireTimeOption"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
        />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">

      <el-button size="medium" @click="cancel">取消</el-button>
      <el-button size="medium" :disabled="btnDisabled" type="primary" @click="emendTimeBtn">保 存</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { updateEnterpriseExpiryTime } from '@/api/enterprise/everday'
import { getBasisById } from '@/api/enterprise/basis'
export default {
  name: 'ExpiryTime',
  data() {
    return {
      dialogTitle: '',
      dialogVisible: false,
      // 查看对话框表单
      LookDialogForm: {
        id: '',
        enterpriseExpiryTime: ''
      },
      btnDisabled: false,
      expireTimeOption: {
        disabledDate(date) {
          return date.getTime() <= Date.now()
        }
      }
    }
  },
  methods: {
    expiryTimeAdd(id) {
      this.dialogTitle = '修改企业到期时间'
      this.getEnterpriseInfo(id)
      this.dialogVisible = true
    },
    // 修改时间对话框确认按钮
    emendTimeBtn() {
      const lookDialogForm = this.LookDialogForm
      this.btnDisabled = true
      updateEnterpriseExpiryTime(lookDialogForm).then(resp => {
        if (resp) {
          this.msgSuccess('修改使用时间成功!')
          this.dialogVisible = false
        } else {
          this.msgError(resp.message)
        }
        this.btnDisabled = false
      })
    },
    // 修改时间对话框取消按钮
    cancel() {
      this.dialogVisible = false
      this.btnDisabled = false
    },
    getEnterpriseInfo(id) {
      getBasisById(id).then(resp => {
        if (resp) {
          this.LookDialogForm.id = resp.data.id
          this.LookDialogForm.enterpriseExpiryTime = resp.data.enterpriseExpiryTime
        }
      })
    }
  }
}
</script>

<style>

</style>
